﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RenderHeads.Media.AVProVideo;

public class AVProPlayerControl : MonoBehaviour
{
    private MediaPlayer mediaPlayer;
    private DisplayUGUI displayUGUI;
    private void Awake()
    {
        displayUGUI = GetComponent<DisplayUGUI>();
        //mediaPlayer = GameObject.Find("MediaPlayer").GetComponent<MediaPlayer>();
    }
    public void FindMediaPlayerCompnent(Transform targetTrans)
    {
        mediaPlayer = targetTrans.GetComponent<MediaPlayer>();
        displayUGUI._mediaPlayer = mediaPlayer;
        mediaPlayer.OpenVideoFromFile( MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, "avvideo/CGA.mp4");
    }
	public void FindMediaPlayerCompnentUrl(Transform targetTrans,string videoPath)
	{
		mediaPlayer = targetTrans.GetComponent<MediaPlayer>();
		displayUGUI._mediaPlayer = mediaPlayer;
		mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL,videoPath);
	}
    public void FindMediaPlayerCompnent(Transform targetTrans, string videoPath)
    {
        mediaPlayer = targetTrans.GetComponent<MediaPlayer>();
        displayUGUI._mediaPlayer = mediaPlayer;
        mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, videoPath);
    }
    public void Play()
    {
        if (mediaPlayer)
        {
            mediaPlayer.Control.Play();
        }
    }
    public void Stop()
    {
        if (mediaPlayer)
        {
            mediaPlayer.Control.Stop();
        }
    }
    public void Pause()
    {
        if (mediaPlayer)
        {
            mediaPlayer.Control.Pause();
        }
    }
    public void Rewind()
    {
        if (mediaPlayer)
        {
            mediaPlayer.Control.Rewind();
        }
    }
    public bool CanPlay()
    {
        if (mediaPlayer)
        {
            return mediaPlayer.Control.CanPlay();
        }
        return false;
    }
    public bool IsPlaying()
    {
        if (mediaPlayer)
        {
            return mediaPlayer.Control.IsPlaying();
        }
        return false;
    }
    public bool IsPaused()
    {
        if (mediaPlayer)
        {
            return mediaPlayer.Control.IsPaused();
        }
        return false;
    }
    public bool IsFinished()
    {
        if (mediaPlayer)
        {
            return mediaPlayer.Control.IsFinished();
        }
        return false;
    }
}
